<!--
 * @Author: zhangyun
 * @Date: 2021-04-20 15:29:57
 * @LastEditors: zhangyun
 * @LastEditTime: 2021-04-28 10:43:38
 * @Desc: 
-->
<template>
  <Header :links="links" :fixed="headerFixed"></Header>
  <Main />
</template>

<script lang="ts">
import { defineComponent, reactive, ref, provide } from 'vue'
import Header from './components/Header.vue'
import Main from './components/Main.vue'

export default defineComponent({
  name: 'App',
  components: {
    Header,
    Main,
  },
  setup(props) {
    const links = ref<Array<any>>([
      { id: 'home', name: '首页', page: 'home' },
      { id: 'member', name: '会员', page: 'member' },
      { id: 'found', name: '发现', page: 'found' },
    ])
    let headerFixed = ref<boolean>(false)
    let createCenterFixed = ref<boolean>(false)
    // 注入公共props
    provide('commonProps', {
      createCenterFixed,
    })
    // 监听滚动条 触发页面固定模块固定
    window.addEventListener('scroll', () => {
      const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      headerFixed.value = scrollTop > 50
      createCenterFixed.value = scrollTop > 140
    })
    return {
      links,
      headerFixed,
    }
  },
})
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
</style>
